package cn.ytr.crm.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 实体类 客户表
 */
@Getter
@Setter
public class Customer extends BaseDomain{

    //客户状态常量
    public static final int STATUS_COMMON = 0;  //潜在客户
    public static final int STATUS_POOL = 1;    //资源池客户
    public static final int STATUS_NORMAL = 2;  //正式客户
    public static final int STATUS_FALL = 3;    //开发失败客户
    public static final int STATUS_LOST = 4;    //流失客户

    //客户ID
    private Long id;

    //姓名
    private String name;

    //年龄
    private Integer age;

    //性别
    private Integer gender;

    //电话
    private String tel;

    //QQ
    private String qq;

    //职业
    private SystemDictionaryItem job;

    //来源
    private SystemDictionaryItem source;

    //销售员
    private Employee seller;

    //录入人
    private Employee inputUser;

    //录入时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date inputTime;

    //状态
    private Integer status = STATUS_COMMON;

    //客户状态常量
    public String getStatusName() {
        String temp = "潜在客户";
        switch (status) {
            case STATUS_COMMON: //0
                temp = "潜在客户";
                break;
            case STATUS_POOL:   //1
                temp = "资源池客户";
                break;
            case STATUS_NORMAL: //2
                temp = "正式客户";
                break;
            case STATUS_FALL:   //3
                temp = "开发失败客户";
                break;
            case STATUS_LOST:   //4
                temp = "流失客户";
                break;
        }
        return temp;
    }

    //用来返回 json 数据的
    public String getJsonString() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("name", name);
        map.put("age", age);
        map.put("gender", gender);
        map.put("tel", tel);
        map.put("qq", qq);
        map.put("status", status);
        if(job != null) {
            map.put("jobId", job.getId());
        }
        if(source != null) {
            map.put("sourceId", source.getId());
        }
        if(seller != null) {
            map.put("sellerId", seller.getId());
            map.put("sellerName", seller.getName());
        }
        return JSON.toJSONString(map);
    }

    //客户性别
    public String getGenderDisplay() {
        return gender == 0 ? "女" : "男";
    }

}








































